﻿using DeepZoomPivotConstructor.PivotLib;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using DeepZoomPivotConstructor.VisualLib;
using System.Linq;
using System.Drawing;

namespace t_PivotLib
{

    /// <summary>
    ///This is a test class for PivotImageTest and is intended
    ///to contain all PivotImageTest Unit Tests
    ///</summary>
    [TestClass()]
    public class t_PivotImage
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for PivotImage Constructor
        ///</summary>
        [TestMethod()]
        public void PivotImageConstructorTest()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v);
            Assert.AreEqual(v, target.Image, "The image visual was not set correctly!");
        }

        [TestMethod]
        public void TestBasicAccessors()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v);

            target.Name = "NameMe";
            Assert.AreEqual("NameMe", target.Name, "Name isn't set");

            target.Description = "This is a test";
            Assert.AreEqual("This is a test", target.Description, "Description didn't make it!");
        }

        [TestMethod]
        public void TestStringFacet()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v) { { "F1", "value1" }, { "F2", "value2" } };
            Assert.AreEqual(2, target.Count(), "Wrong number of added meta data");
        }

        [TestMethod]
        public void TestURLFacet()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v) { { "F1", "nytimes", new Uri("http://www.nytimes.com") }, { "F2", "CNN", new Uri("http://www.cnn.com") } };
            Assert.AreEqual(2, target.Count(), "Wrong number of added meta data");
        }

        [TestMethod]
        public void TestNumberFacet()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v) { { "F1", 5 }, { "F2", (decimal) 55.5 } };
            Assert.AreEqual(2, target.Count(), "Wrong number of added meta data");
        }

        [TestMethod]
        public void TestDatTimeFacet()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v) { { "F1", DateTime.Now }, { "F2", DateTime.Now } };
            Assert.AreEqual(2, target.Count(), "Wrong number of added meta data");
        }

        [TestMethod]
        public void TestFetchMetadata()
        {
            Visual v = new VisualBitmapImage(1.0, 1.0, 100, Color.Black);
            PivotImage target = new PivotImage(v) { { "F1", DateTime.Now }, { "F2", DateTime.Now }, { "F4", "CNN", new Uri("http://www.cnn.com") } };

            var result = target.GetMetadata<PivotMetadataDateTime>("F1");
            Assert.AreEqual(1, result.Count(), "Expected to get back my meta-data!");

            var result2 = target.GetMetadata<PivotMetadataURL>("F4");
            Assert.AreEqual(1, result2.Count(), "Expected to get back the URL meta data I wanted!");

        }
    }
}